import 'package:appflutterhomeschool/api/api_service.dart';
import 'package:appflutterhomeschool/api/dio_utils.dart';
import 'package:appflutterhomeschool/ui/widgets/academic_sentiment/discount_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/my_app_bar.dart';
import 'package:appflutterhomeschool/view_model/my_app_view_model.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

///用户： ninetailedfox
///时间： 2020/7/6
///邮箱： 1037438704@qq.com
///功能： 成绩曲线

class PerformanceCurvePage extends StatefulWidget {
  @override
  _PerformanceCurvePageState createState() => _PerformanceCurvePageState();
}

class _PerformanceCurvePageState extends State<PerformanceCurvePage> {
  List listMap;
  MyAppViewModel myAppViewModel;

  @override
  Widget build(BuildContext context) {
    myAppViewModel = Provider.of(context);
    Map<String, dynamic> map = myAppViewModel.identity
        ? {
      "cls_mapping_id":
      myAppViewModel.studentInformationModel.classMappingId,
    }
        : {
      "cls_id": myAppViewModel.studentInformationModel.classId,
      "student_id": myAppViewModel.studentInformationModel.subjectId,
    };
    DioUtils.getInstance().post(ApiService.getStudentScores, map,
            (successCallBack) {
          if (successCallBack == null || successCallBack["data"] == null) {
            return;
          }
          Map<String, dynamic> data = successCallBack["data"];
          listMap = [];
          (data["scores"] as List).forEach((element) {
            listMap.add(element);
          });
          setState(() {});
        }, (errorCallBack) {});
    return Scaffold(
      appBar: MyAppBar2(title: "成绩曲线"),
      body: listMap == null
          ? Center(child: CircularProgressIndicator())
          : ListView.builder(
              shrinkWrap: true,
              itemCount: listMap.length,
              itemBuilder: (context, index) {
                return DiscountWidget(
                  mapScore: listMap[index],
                );
              }),
    );
  }
}
